package me.guythundar.NoChat;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class NoChatCommander implements CommandExecutor {


	public NoChat plug;
	
	public NoChatCommander(NoChat noChat) {
		plug = noChat;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label,
			String[] args) {
		
		Player p = ( sender instanceof Player ) ? (Player) sender : null;
		
		if ( p != null ){
			if ( cmd.getName().equalsIgnoreCase("hear") && args.length == 1) {
				if ( args[0].equalsIgnoreCase("all") ) {
					plug.setHearingLevel(p, plug.HEAR_ALL);
					return true;
				}
				else if ( args[0].equalsIgnoreCase("chat") ) {
					plug.setHearingLevel(p, plug.HEAR_CHAT_ONLY);
					return true;
				}
				else if ( args[0].equalsIgnoreCase("command") ){
					plug.setHearingLevel(p, plug.HEAR_COMMANDS_ONLY);
					return true;
				}
				else if ( args[0].equalsIgnoreCase("none") ){
					plug.setHearingLevel(p, plug.HEAR_NONE);
					return true;
				}
				else { return false; }
			}
		}
		else {
			sender.sendMessage("You must be a player to use this command.");
			return true;
		}		
		return false;
	}
	
}
